home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / kms20src.lha / KMSC / kms.c < prev    next >
C/C++ Source or Header  |  1995-09-16  |  7KB  |  307 lines

  1. /**********************************
  2.  *              KMS               *
  3.  **********************************/
  4.  
  5. /*************************************************************************
  6.  *
  7.  *   Copyright (C) 1995 Thomas Schwarz
  8.  *                      <kmshq@ruatha.muc.de>
  9.  *                      <Schwarz.Thomas@fhm.de>
  10.  *
  11.  *   This program is free software; you can redistribute it and/or modify
  12.  *   it under the terms of the GNU General Public License as published by
  13.  *   the Free Software Foundation; either version 2 of the License, or
  14.  *   any later version.
  15.  *
  16.  *   This program is distributed in the hope that it will be useful,
  17.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *   GNU General Public License for more details.
  20.  *
  21.  *   You should have received a copy of the GNU General Public License
  22.  *   along with this program; if not, write to the Free Software
  23.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  *
  25.  *************************************************************************/
  26.  
  27. #include <KMS/KMS.h>
  28. #include <KMS/KMS_devlib.h>
  29.  
  30. Prototype UWORD Break(VOID);
  31. Prototype VOID wbmain(struct WBStartup *);
  32. Prototype VOID main(UWORD, STRPTR *);
  33. Prototype VOID HandleCall(VOID);
  34. Prototype VOID WaitForCall(VOID);
  35.  
  36. extern VOID KPrintF(APTR, ...);
  37.  
  38. /*****************************
  39.  * Externe Globale Variablen *
  40.  *****************************/
  41.  
  42. extern struct KMSBase *KMSBase;
  43. extern struct LocalConfig *KMS_LC;
  44.  
  45. extern UMSAccount MyUMSAccount;
  46.  
  47. extern UBYTE Plop;
  48.  
  49. extern struct UserNode DummyUser;
  50.  
  51. /*********************
  52.  * Globale Variablen *
  53.  *********************/
  54.  
  55. struct WBStartup *WBStart = NULL;
  56. UBYTE ShutDown = 0;
  57. BOOL Immediate = FALSE;
  58. BOOL PreLogin = FALSE;
  59. BOOL AutoShutDown = FALSE;
  60. TEXT PreUser[LEN_USERNAME+1];
  61.  
  62. /******************************************
  63.  * Break-Handler                          *
  64.  ******************************************
  65.  * I: ---                                 *
  66.  * O: 0                                   *
  67.  ******************************************/
  68.  
  69. /// "Break"
  70.  
  71. UWORD Break(VOID)
  72.    {
  73.    return 0;
  74.    }
  75.  
  76. ///
  77.  
  78. /******************************************
  79.  * Hauptprogramm (Workbench-Einsprung)    *
  80.  ******************************************
  81.  * I: Argumente                           *
  82.  * O: ---                                 *
  83.  ******************************************/
  84.  
  85. /// "wbmain"
  86.  
  87. VOID wbmain(struct WBStartup *wbs)
  88.    {
  89.    WBStart = wbs;
  90.  
  91.    main(0, NULL);
  92.    }
  93.  
  94. ///
  95.  
  96. /******************************************
  97.  * Hauptprogramm                          *
  98.  ******************************************
  99.  * I: Argumente                           *
  100.  * O: ---                                 *
  101.  ******************************************/
  102.  
  103. /// "main"
  104.  
  105. VOID main(UWORD argc, STRPTR *argv)
  106.    {
  107.    onbreak(Break);
  108.  
  109.    if(OpenLib())
  110.       Sense(20);
  111.    if(OpenTimer())
  112.       Sense(20);
  113.    if(Identify())
  114.       Sense(20);
  115.  
  116.    /* Dummy-User initialisieren */
  117.  
  118.    InitUser(&DummyUser.UserData);
  119.    KMS_LC->Session.CurrentUser = &DummyUser;
  120.    
  121.    if(WBStart && ParseToolTypes(WBStart))
  122.       Sense(20);
  123.    else if(!WBStart && ParseArgs())
  124.       Sense(20);
  125.    if(OpenDisplay())
  126.       Sense(20);
  127.  
  128.    FlushInput();
  129.  
  130.    KMS_LC->Session.Echo = FALSE; /* Echo aus */
  131.  
  132.    SysMsg(KMS_OPEN_CLIENT);
  133.  
  134.    while(!ShutDown)
  135.       {
  136.       WaitForCall();
  137.  
  138.       if(!ShutDown)
  139.          {
  140.          Plop = 0;
  141.  
  142.          KMS_LC->Session.HistPoint = KMS_LC->HistoryList.mlh_Head;
  143.          KMS_LC->Session.LoginTime = time(NULL);   /* Startzeit festhalten */
  144.          KMS_LC->Session.MaxConnectTime = KMSBase->MaxConnectTime; /* Maximal-Verbindungszeit */
  145.          KMS_LC->Session.Warnings = 0;             /* Inputtimeout-Warnungen = 0 */
  146.          KMS_LC->Session.Echo = TRUE;              /* Echo ein */
  147.          KMS_LC->Session.CommMode = 0;             /* Port-Msgs erlaubt */
  148.          KMS_LC->Session.Refresh = FALSE;
  149.          *KMS_LC->Session.Password = '\0';
  150.          *KMS_LC->Session.CurrCmd = '\0';
  151.  
  152.          MsgPrint(NULL, 0);
  153.          ReadMsg(0, RF_RESET);
  154.  
  155.          /* Anruf bearbeiten */
  156.  
  157.          HandleCall();
  158.          }
  159.  
  160.       Immediate = FALSE;
  161.       PreLogin = FALSE;
  162.       *PreUser = '\0';
  163.  
  164.       if(AutoShutDown)
  165.          ShutDown = SHUTDOWN_IMMEDIATE;
  166.       }
  167.  
  168.    CursorOn();
  169.  
  170.    LogEntry(NULL);
  171.  
  172.    Sense(0);
  173.    }
  174.  
  175. ///
  176.  
  177. /*******************
  178.  * Zentral-Routine *
  179.  *******************
  180.  * I: ---          *
  181.  * O: ---          *
  182.  *******************/
  183.  
  184. /// "HandleCall"
  185.  
  186. VOID HandleCall(VOID)
  187.    {
  188.    if(KMSLogin())
  189.       {
  190.       HandleSession();
  191.  
  192.       KMSLogout();
  193.       }
  194.  
  195.    if(KMS_LC->Device & DEV_SERIAL)
  196.       Hangup();
  197.    }
  198.  
  199. ///
  200.  
  201. /*****************************
  202.  * Auf nächsten Anruf warten *
  203.  *****************************
  204.  * I: ---                    *
  205.  * O: ---                    *
  206.  *****************************/
  207.  
  208. /// "WaitForCall"
  209.  
  210. extern struct MsgPort *WritePort;
  211.  
  212. VOID WaitForCall(VOID)
  213.    {
  214.    BOOL res;
  215.    BOOL exit = FALSE;
  216.  
  217.    CursorOn();
  218.  
  219.    FlushInput();
  220.  
  221.    if(Immediate)
  222.       {
  223.       /* Sofort-Login */
  224.  
  225.       SetMode(KMS_LC->InHandle, 2); /* Carrier-Check EIN */
  226.       
  227.       exit = TRUE;
  228.       }
  229.    else
  230.       {
  231.       /* Modemreset */
  232.  
  233.       SetMode(KMS_LC->InHandle, 4); /* Carrier-Check AUS */
  234.    
  235.       if(KMS_LC->Device & DEV_SERIAL)
  236.          ResetModem();
  237.       }
  238.  
  239.    /* Auf Anruf bzw. RETURN von Konsole warten */
  240.  
  241.    while(!exit)
  242.       {
  243.       FlushInput();
  244.  
  245.       Plop = 0;
  246.       
  247.       KMS_LC->Session.LineSpeed = 0;
  248.  
  249.       if(KMS_LC->Device & DEV_SERIAL)
  250.          {
  251.          /* Eine Minute auf "RING" warten */
  252.  
  253.          res = ModemWait(60, KMSBase->ModemRingString);
  254.          }
  255.       else
  256.          {
  257.          /* Eine Minute auf [Return] von Tastatur warten */
  258.  
  259.          res = ModemWait(60, "\r");
  260.          }
  261.  
  262.       /* Falls ShutDown-Kommando kam, Schluß machen */
  263.  
  264.       if(ShutDown)
  265.          {
  266.          CursorOff();
  267.          return;
  268.          }
  269.  
  270.       /* Falls nicht gerade Logins gesperrt sind, Input auswerten */
  271.  
  272.       if(res && !KMS_LC->Locked)
  273.          {
  274.          /* Modem oder Tastatur? */
  275.  
  276.          if(KMS_LC->Device & DEV_SERIAL)
  277.             {
  278.             /* Telefoooooon! Wenn CONNECT, dann raus */
  279.  
  280.             if (!MyUMSAccount && AnswerPhone())
  281.                {
  282.                SetMode(KMS_LC->InHandle, 2); /* Carrier-Check EIN */
  283.  
  284.                exit = TRUE;
  285.                }
  286.             else
  287.                Hangup();
  288.             }
  289.          else if(KMS_LC->Device & DEV_CONSOLE)
  290.             {
  291.             /* Lokale Sitzung */
  292.  
  293.             if(!MyUMSAccount) /* (Wenn kein REXX-Login!) */
  294.                exit = TRUE;
  295.             }
  296.          }
  297.       }
  298.  
  299.    FlushInput();
  300.  
  301.    SysMsg(KMS_START_SESSION);
  302.  
  303.    CursorOff();
  304.    }
  305.  
  306. ///
  307.